package adger.me.yili.view.impl;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.flyco.tablayout.SegmentTabLayout;

import org.xutils.db.sqlite.WhereBuilder;

import java.util.ArrayList;

import adger.me.yili.R;
import adger.me.yili.utils.SharePreferencesUtil;
import adger.me.yili.utils.ViewFindUtils;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderActivity extends AppCompatActivity {
    @Bind(R.id.title)
    TextView title;
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private String[] mTitles = {"全部订单", "未领取", "已领取"};
    private View mDecorView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_segment_tab);
        ButterKnife.bind(this);
        title.setText(SharePreferencesUtil.getSpString("curryGroup_no", "", this)+"期 订单汇总");
        initFragmentAndTab();
    }

    /**
     * 初始化tab和对应的fragment
     */
    private void initFragmentAndTab() {
        mFragments.add(AllOrderFragment.getInstance(mTitles[0], null));
        mFragments.add(AllOrderFragment.getInstance(mTitles[1], WhereBuilder.b("claimed", "!=", 1)));
        mFragments.add(AllOrderFragment.getInstance(mTitles[2], WhereBuilder.b("confirmed", "=", 1).and("claimed", " = ", 1)));
//        mFragments.add(NotOrderFragment.getInstance(mTitles[1]));
//        mFragments.add(EndOrderFragment.getInstance(mTitles[2]));

        mDecorView = getWindow().getDecorView();

        SegmentTabLayout tabLayout = ViewFindUtils.find(mDecorView, R.id.tab);

        tabLayout.setTabData(mTitles, this, R.id.fl_change, mFragments);
        // 设置未读
        //tabLayout.showDot(1);
    }

    @OnClick(R.id.ll_menu_left)
    public void onClick() {
        finish();
    }
}
